package com.jingjiu.homeservicesbiz.controller;

import java.util.List;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jingjiu.homeservicesapi.domain.MessageBoard;
import com.jingjiu.homeservicesapi.util.R;
import com.jingjiu.homeservicesbiz.service.MessageBoardServiceImpl;


import org.springdoc.core.annotations.ParameterObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


/**
 * 留言板：记录用户的留言信息Controller
 * 
 * @author ruoyi
 * @date 2025-04-16
 */
@RestController
@RequestMapping("/system/board")
public class MessageBoardController
{

    @Autowired
    private MessageBoardServiceImpl messageBoardService;

    @GetMapping("/page")
    @ResponseBody
    public R<Page<MessageBoard>> getPage(@ParameterObject Page<MessageBoard> page,
                                         @ParameterObject MessageBoard messageBoard) {

        Page<MessageBoard> messageBoardPage = messageBoardService.selectPage(page, messageBoard);
        if(messageBoardPage==null)
            return R.failed();
        return R.ok(messageBoardPage);
    }




    /**
     * 新增保存留言板：记录用户的留言信息
     */

    @PostMapping("/add")
    @ResponseBody
    public R addSave(@RequestBody MessageBoard messageBoard)
    {
      int row = messageBoardService.insertMessageBoard(messageBoard);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 修改留言板：记录用户的留言信息
     */

    @GetMapping("/get/{id}")
    public R<MessageBoard> get(@PathVariable("id") Long id)
    {
        MessageBoard messageBoard = messageBoardService.selectMessageBoardById(id);
        if(messageBoard==null)
            return R.failed();
         return R.ok(messageBoard);

    }

    /**
     * 修改保存留言板：记录用户的留言信息
     */

    @PostMapping("/edit")
    @ResponseBody
    public R editSave(@RequestBody MessageBoard messageBoard)
    {
        int row = messageBoardService.updateMessageBoard(messageBoard);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }

    /**
     * 删除留言板：记录用户的留言信息
     */

    @PostMapping( "/remove")
    @ResponseBody
    public R remove(Long id)
    {
        int row = messageBoardService.deleteMessageBoardById(id);
        if(row!=1)
            return R.failed();
        return R.ok(row);
    }
}
